//
//  MQStatus.swift
//  MQWeibo
//
//  Created by 毛强 on 16/1/1.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class MQStatus: NSObject {
    
    var id: Int64 = 0
    /// 微博的内容
    var text: String?
    /// 微博的创建时间
    var created_at: String?
    /// 微博的来源
    var source: String?
    /// 当前微博的作者信息
    var user: MQUser?
    /// 转发微博的字段
    var retweeted_status: MQStatus?
    
    /// 转发评论赞 的数量
    var reposts_count: Int = 0
    var comments_count: Int = 0
    var attitudes_count: Int = 0
    
    var pic_urls:[MQStatusPictureInfo]?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                // 字典转模型
                user = MQUser(dict: dict)
            }
        }else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                // 字典转模型
                retweeted_status = MQStatus(dict: dict)
            }
        }else if key == "pic_urls"{
            if let dicts = value as?[[String: NSObject]]{
                pic_urls = [MQStatusPictureInfo]()
                
                for dict in dicts {
                    let pictureInfo = MQStatusPictureInfo(dict: dict )
                    pic_urls?.append(pictureInfo)
                }
            }
        } else{
            // 在此一定要调用 super ，因为 super 方法才是真正赋值
            super.setValue(value, forKey: key)
        }
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}

}
